package yannan.voiplock4ble.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import yannan.voiplock4ble.BuildConfig;
import yannan.voiplock4ble.R;
import yannan.voiplock4ble.adapter.base.BaseAutoLoadingAdapter;
import yannan.voiplock4ble.adapter.base.IMyOnScrollListener;
import yannan.voiplock4ble.adapter.base.MyViewHolder;
import yannan.voiplock4ble.adapter.base.RecyclerViewBaseAdapter;
import yannan.voiplock4ble.bean.LockRecordBean;

/**
 * 说明：开锁记录列表适配器
 * 作者：mainTel
 * 时间：2016/8/24 17:35
 * 备注：
 */
public class LockRecordAdapter extends BaseAutoLoadingAdapter<LockRecordBean> {

    public LockRecordAdapter(List<LockRecordBean> list, Context ctx, RecyclerView recyclerView) {
        super(list, ctx, recyclerView);
    }

    @Override
    public int createFootView() {
        return 0;
    }

    @Override
    public int createItemView() {
        return R.layout.item_lock_record;
    }

    @Override
    public void onItemBindViewHolder(MyViewHolder holder, int poi) {
        LockRecordBean bean = list.get(poi);
        String time = bean.unlockingDate.split(" ")[0];

        try {
            if (!TextUtils.equals(time, list.get(poi - 1).getUnlockingDate().split(" ")[0])) { //如果和前面的不一样
                holder.get(R.id.ll_head_title).setVisibility(View.VISIBLE);
                holder.setTextView(R.id.tv_head_title, time);
                holder.get(R.id.line_top).setVisibility(View.INVISIBLE);
            } else {
                holder.get(R.id.ll_head_title).setVisibility(View.GONE);
                holder.get(R.id.line_top).setVisibility(View.VISIBLE);
            }
        } catch (Exception e) {
            e.printStackTrace();
            //TODO 切换的时候，状态是不是应该是GONE
            holder.get(R.id.ll_head_title).setVisibility(View.VISIBLE);
            holder.get(R.id.line_top).setVisibility(View.INVISIBLE);
        }

        try {
            if (!TextUtils.equals(time, list.get(poi + 1).getUnlockingDate().split(" ")[0])) { //如果和后面的不一样
                holder.get(R.id.line_bottom).setVisibility(View.INVISIBLE);
            } else {
                holder.get(R.id.line_bottom).setVisibility(View.VISIBLE);
            }
        } catch (Exception e) {
            e.printStackTrace();
            holder.get(R.id.line_bottom).setVisibility(View.INVISIBLE);
        }
        holder.setTextView(R.id.tv_unlock_time, bean.getUnlockingDate().split(" ")[1]);
        holder.getConvertView().setContentDescription(time);
        if (bean.getUnlockinType().equals("0")) {
            holder.setTextView(R.id.tv_number, bean.userIdentifier);

        } else {
            holder.setTextView(R.id.tv_number, "KEY" + bean.userIdentifier);
        }
        if (bean.nickName != null) {
            holder.setTextView(R.id.tv_name, bean.nickName);
        } else {
            holder.setTextView(R.id.tv_name, "");
            holder.get(R.id.tv_name).setVisibility(View.GONE);
        }
    }

    @Override
    public void onFootBindViewHolder(MyViewHolder holder, int poi) {

    }
}
